package sv.gob.mh.dgii.html.editor;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SiitDateEditor extends SiitEditor {

    protected final static Log log = LogFactory.getLog(SiitDateEditor.class);
    public final static String DEFAULT_PATTERN = "dd/MM/yyyy";
    public final static String FULL_PATTERN = "yyyy.MM.dd G 'at' hh:mm:ss z";

    public SiitDateEditor() {
        super(DEFAULT_PATTERN);
    }

    public SiitDateEditor(String format) {
        super(format);
    }

    @Override
    public void setAsText(String value) {
        try {
            setValue(new SimpleDateFormat(format).parse(value));
        } catch (Exception e) {
            setValue(null);
        }
    }

    @Override
    public String getAsText() {
        String ret = null;
        try {
            ret = new SimpleDateFormat(format).format((Date) getValue());
        } catch (Exception e) {
        }
        return ret;
    }
}
